package com.thinking.in.spring.bean.definition;

import com.thinking.in.spring.bean.factory.UserFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author zjiajia
 * @date 2021/12/28 20:48
 */
public class BeanGarbageCollectionDemo {


    public static void main(String[] args) throws InterruptedException {


        // 创建容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        // 注册配置类
        applicationContext.register(BeanInitializationDemo.class);
        // 启动
        System.out.println("应用上下文准备启动===============");
        applicationContext.refresh();
        System.out.println("应用上下文完成启动================");

        // 依赖查找
        UserFactory userFactory = applicationContext.getBean(UserFactory.class);

        System.out.println(userFactory);
        // 关闭
        System.out.println("应用上下文准备关闭。。。。");
        applicationContext.close();
        System.out.println("应用上下文完成关闭。。。。");

        Thread.sleep(1000L);
        System.gc();
        Thread.sleep(1000L);
    }
}
